package com.example.flshtarvel.controller;

import com.example.flshtarvel.entity.TagType;
import com.example.flshtarvel.service.TagTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TagTypeController {
    @Autowired
    TagTypeService tagTypeService;

    @GetMapping("/tagType/{tagTypeId}")
    public Map<String,Object> selectTagTypeById(@PathVariable("tagTypeId") String tagTypeId){
        Map<String,Object> map = new HashMap<String,Object>();
        TagType tagType = tagTypeService.selectTagTypeById(tagTypeId);
        if(tagType==null){
            map.put("msg",0);
        }else{
            map.put("msg",1);
            map.put("tagType",tagType);
        }
        return map;
    }

    @PostMapping("/tagType")
    public Map<String,Object> insertTagType(TagType tagType){
        Map<String,Object> map = new HashMap<String,Object>();
        int tag  = tagTypeService.insertTagType(tagType);
        if(tag==1){
            map.put("msg",1);
            map.put("tagType",tagType);
        }else{
            map.put("msg",0);
        }
        return map;
    }

    @GetMapping("/tagType")
    public Map<String,Object> selectAllTagType(){
        Map<String,Object> map = new HashMap<String,Object>();
        List<TagType> tagTypeList = tagTypeService.selectAllTagType();
        if(tagTypeList.isEmpty()){
            map.put("msg",0);
        }else{
            map.put("msg",1);
            map.put("tagTypeList",tagTypeList);
        }
        return map;
    }
}
